package com.gitee.wsl.mathematics.matrix.mat2

import com.gitee.wsl.ext.array.DoubleArray
import com.gitee.wsl.io.dataproxy.DataGet
import com.gitee.wsl.io.dataproxy.asProxy
import com.gitee.wsl.mathematics.matrix.M
import com.gitee.wsl.mathematics.matrix.N
import com.gitee.wsl.mathematics.vector.vec2.Vec2
import com.gitee.wsl.mathematics.vector.vec2.Vector2


open class Mat2(m00: Double=0.0, m01: Double=0.0,
                m10: Double=0.0, m11: Double=0.0,
                override val proxy: DataGet<Double> = DoubleArray(m00, m01,m10, m11).asProxy())
    :Matrix2D<Mat2, Vec2> {

    override val self
        get() = this


    override val m by lazy{listOf(M[0],M[1])}

    override val n by lazy {listOf(N[0],N[1])}

    override fun createVec(indexes: List<Int>) = Vec2(proxy = proxy.asProxy(indexes))

    override fun createVec2(x: Double, y: Double) = Vec2(x,y)

    override fun toMutable() = MutableMat2(this)

    override fun create(m00: Double, m01: Double, m10: Double, m11: Double) = Mat2(m00, m01, m10, m11)

    override fun hashCode(): Int =
        m00.hashCode() xor
                (m01.hashCode() xor 0x75A5A5A5) xor
                (m10.hashCode() xor 0x5A5A5A5A) xor
                (m11.hashCode() xor 0x76969696)

    override fun equals(other: Any?) =
        other is Mat2 &&
                m00 approx  other.m00 &&
                m01 approx other.m01 &&
                m10 approx other.m10 &&
                m11 approx other.m11

    override fun toString() = "(($m00, $m01),\n ($m10, $m11))"

}
